//package com.anti.modular.bus.houselease.service.impl;
//
//import cn.hutool.core.bean.BeanUtil;
//import cn.hutool.core.collection.CollectionUtil;
//import cn.hutool.core.date.DateTime;
//import cn.hutool.core.date.DateUtil;
//import cn.hutool.core.util.ObjectUtil;
//import com.anti.commom.core.exception.BusinessException;
//import com.anti.commom.core.utils.DecimalUtils;
//import com.anti.core.context.login.LoginContextHolder;
//import com.anti.core.utils.IdFlowingUtil;
//import com.anti.jdbc.DBUtils;
//import com.anti.jdbc.support.page.PageParam;
//import com.anti.jdbc.support.page.PageResult;
//import com.anti.modular.bus.billrentadjustment.param.BillRentAdjustmentParam;
//import com.anti.modular.bus.billrentadjustment.service.BillRentAdjustmentService;
//import com.anti.modular.bus.busbasicsettings.entity.BusBasicSettings;
//import com.anti.modular.bus.busbasicsettings.service.BusBasicSettingsService;
//import com.anti.modular.bus.busroom.entity.BusRoom;
//import com.anti.modular.bus.busroom.param.BusRoomParam;
//import com.anti.modular.bus.busroom.service.BusRoomService;
//import com.anti.modular.bus.housebill.entity.HouseBill;
//import com.anti.modular.bus.housebill.service.HouseBillService;
//import com.anti.modular.bus.housebilldetail.entity.HouseBillDetail;
//import com.anti.modular.bus.housebilldetail.service.HouseBillDetailService;
//import com.anti.modular.bus.houselease.entity.HouseLease;
//import com.anti.modular.bus.houselease.enums.HouseLeaseExceptionEnum;
//import com.anti.modular.bus.houselease.param.HouseLeaseParam;
//import com.anti.modular.bus.houselease.result.HouseLeaseResult;
//import com.anti.modular.bus.houselease.service.HouseLeaseService;
//import com.anti.modular.bus.houselease.vo.DayCompare;
//import com.anti.modular.bus.houselease.vo.TimeVo;
//import com.anti.modular.bus.houseleaselive.entity.HouseLeaseLive;
//import com.anti.modular.bus.houseleaselive.service.HouseLeaseLiveService;
//import com.anti.modular.bus.hydropowermeter.param.HydropowerMeterParam;
//import com.anti.modular.bus.hydropowermeter.service.HydropowerMeterService;
//import com.anti.modular.bus.roomdeposit.result.RoomDepositResult;
//import com.anti.modular.bus.roomdeposit.service.RoomDepositService;
//import com.anti.modular.bus.roomexpenses.result.RoomExpensesResult;
//import com.anti.modular.bus.roomexpenses.service.RoomExpensesService;
//import com.anti.modular.bus.roomfurniture.result.RoomFurnitureResult;
//import com.anti.modular.bus.roomfurniture.service.RoomFurnitureService;
//import org.springframework.stereotype.Service;
//
//import javax.annotation.Resource;
//import java.math.BigDecimal;
//import java.text.DateFormat;
//import java.text.ParseException;
//import java.text.SimpleDateFormat;
//import java.util.ArrayList;
//import java.util.Calendar;
//import java.util.Date;
//import java.util.List;
//
///**
// * 房间租约service接口实现类
// *
// * @author anti
// * @date 2021-05-06 09:30:21
// */
//@Service
//public class HouseLeaseServiceImplBak implements HouseLeaseService {
//    @Resource
//    DBUtils dbUtils;
//    @Resource
//    HouseLeaseLiveService houseLeaseLiveService;
//    @Resource
//    HouseBillService houseBillService;
//    @Resource
//    HouseBillDetailService houseBillDetailService;
//    @Resource
//    BusRoomService busRoomService;
//    @Resource
//    RoomDepositService roomDepositService;
//    @Resource
//    RoomExpensesService roomExpensesService;
//    @Resource
//    BusBasicSettingsService busBasicSettingsService;
//    @Resource
//    RoomFurnitureService roomFurnitureService;
//    @Resource
//    BillRentAdjustmentService billRentAdjustmentService;
//    @Resource
//    HydropowerMeterService hydropowerMeterService;
//
//    @Override
//    public HouseLease getById(HouseLeaseParam houseLeaseParam){
//        String sql="select * from house_lease where id =? ";
//        return dbUtils.get(sql,HouseLease.class,houseLeaseParam.getId());
//    }
//
//    @Override
//    public PageResult page(PageParam pageParam,HouseLeaseParam houseLeaseParam) {
//        StringBuilder sb=new StringBuilder("select * from house_lease where 1=1 and status =0 ");
//        ArrayList<Object> param = CollectionUtil.newArrayList();
//        if (ObjectUtil.isNotNull(houseLeaseParam)) {
//            // 根据在租房间名称 查询
//            if (ObjectUtil.isNotEmpty(houseLeaseParam.getRoomName())) {
//               sb.append(" and room_name = ?");
//               param.add(houseLeaseParam.getRoomName());
//            }
//            // 根据承租人姓名 查询
//            if (ObjectUtil.isNotEmpty(houseLeaseParam.getName())) {
//               sb.append(" and name = ?");
//               param.add(houseLeaseParam.getName());
//            }
//            // 根据聯係方式 查询
//            if (ObjectUtil.isNotEmpty(houseLeaseParam.getPhone())) {
//               sb.append(" and phone = ?");
//               param.add(houseLeaseParam.getPhone());
//            }
//            // 根据身份证号 查询
//            if (ObjectUtil.isNotEmpty(houseLeaseParam.getIdCard())) {
//               sb.append(" and id_card = ?");
//               param.add(houseLeaseParam.getIdCard());
//            }
//        }
//        return dbUtils.query(pageParam,sb.toString(),param.toArray());
//    }
//
//    @Override
//    public List<HouseLease> list(HouseLeaseParam houseLeaseParam) {
//        String sql="";
//        return dbUtils.query(sql,HouseLease.class);
//    }
//
//    @Override
//    public void add(HouseLeaseParam houseLeaseParam) {
//        checkParam(houseLeaseParam,false);
//        HouseLease houseLease = new HouseLease();
//        BeanUtil.copyProperties(houseLeaseParam, houseLease);
//        Date date = new Date();
//        Long sysLoginUserId = LoginContextHolder.me().getSysLoginUserId();
//        //保存入住信息
//        houseLease.setStatus(0);
//        houseLease.setLeaseStatus(0);
//        houseLease.setCreateTime(date);
//        String zqName = getZqName(houseLeaseParam);
//        houseLease.setReceiptCycle(zqName);
//        houseLease.setCreateUser(sysLoginUserId);
//        String key = dbUtils.insertKey(houseLease).toString();
//        long pkMain = Long.parseLong(key);
//        houseLease.setId(pkMain);
//        //保存同住人信息
//        List<HouseLeaseLive> leaseLiveData = houseLeaseParam.getLeaseLiveData();
//        leaseLiveData.forEach(item ->{
//            item.setLeaseId(pkMain);
//            item.setStatus(0);
//            item.setCreateTime(date);
//            item.setCreateUser(sysLoginUserId);
//            houseLeaseLiveService.add(item);
//        });
//        BusRoomParam roomParam=new BusRoomParam();
//        roomParam.setId(houseLeaseParam.getRoomId());
//        BusRoom busRoom = busRoomService.getById(roomParam);
//        //基础设置
//        BusBasicSettings one = busBasicSettingsService.getOne();
//        //计算费用时月天数 （字典 0按固定30天算 1按月份实际天数
//        int calculateStyle = one.getCalculateStyle();
//        //账单金额取整 （字典 0关闭 1打开 小数点后四舍五入）
//        int amount = one.getAmount();
//        //保存账单信息
//        // 判断水电是否分开
//        int hydropower = busRoom.getHydropower();
//        int receiptYj = houseLease.getReceiptYj();
//        //账单收租日日 （字典 0提前  1 固定）
//        int billEndType = houseLease.getBillEndType();
//        //账单收租日提前几日
//        Integer billEndTqData = houseLease.getBillEndTqData();
//        //账单收租日固定几月（有正负）
//        Integer billEndGdmonthData = houseLease.getBillEndGdmonthData();
//        //账单收租日固定几日
//        Integer billEndGddayData = houseLease.getBillEndGddayData();
//        List<RoomDepositResult> depositList = roomDepositService.getDepositListByRoomId(houseLeaseParam.getRoomId());
//        if (hydropower == 0){
//            List<RoomExpensesResult> expensesList = roomExpensesService.getExpensesListByRoomId(houseLeaseParam.getRoomId(),"");
//            //计算账单期数
//            List<HouseBill> houseBillList = calculateQs(houseLease.getRentStartDate(), houseLease.getRentEndDate(), houseLease.getReceiptFu(), receiptYj);
//            for (int i = 0; i < houseBillList.size(); i++) {
//                HouseBill houseBill= houseBillList.get(i);
//                int qs = i+ 1;
//                houseBill.setBillType(2);
//                houseBill.setQsnum(qs);
//                houseBill.setQs("租金"+qs+"期");
//                addBillBysDNo(amount,calculateStyle,houseBill,houseLease, date, sysLoginUserId, pkMain, receiptYj, billEndType, billEndTqData, billEndGdmonthData, billEndGddayData, depositList, expensesList);
//            }
//        }else {
//            //计算账单期数水电分开
//            List<RoomExpensesResult> expensesList = roomExpensesService.getExpensesListByRoomId(houseLeaseParam.getRoomId(),"1");
//            List<HouseBill> houseBillList = calculateQs(houseLease.getRentStartDate(), houseLease.getRentEndDate(), houseLease.getReceiptFu(), receiptYj);
//            for (int i = 0; i < houseBillList.size(); i++) {
//                HouseBill houseBill= houseBillList.get(i);
//                int qs = i+ 1;
//                houseBill.setBillType(2);
//                houseBill.setQsnum(qs);
//                houseBill.setQs("租金"+qs+"期");
//                addBillBysDNo(amount,calculateStyle,houseBill,houseLease, date, sysLoginUserId, pkMain, receiptYj, billEndType, billEndTqData, billEndGdmonthData, billEndGddayData, depositList, expensesList);
//            }
//
//            //计算水电账单
//            List<RoomExpensesResult> expensesListfk = roomExpensesService.getExpensesListByRoomId(houseLeaseParam.getRoomId(),"2");
//            int hydropowercycle = busRoom.getHydropowercycle();
//            List<HouseBill> houseBills = calculateQs(houseLease.getRentStartDate(), houseLease.getRentEndDate(), hydropowercycle, 2);
//            for (int i = 0; i < houseBills.size(); i++) {
//                HouseBill houseBillsd= houseBills.get(i);
//                int qs = i+ 1;
//                houseBillsd.setQsnum(qs);
//                houseBillsd.setQs("水電"+qs+"期");
//                houseBillsd.setBillType(3);
//                addBillBySdYesZd(houseLease,date, sysLoginUserId, pkMain,busRoom.getBillEndTqData(), billEndGdmonthData, billEndGddayData, expensesListfk, houseBillsd);
//            }
//        }
//        busRoom.setLease(1);
//        busRoom.setLeaseid(pkMain);
//        busRoom.setUpdateTime(date);
//        busRoom.setUpdateUser(sysLoginUserId);
//        dbUtils.update(busRoom);
//
//    }
//
//    private void addBillBySdYesZd(HouseLease houseLease,Date date, Long sysLoginUserId, long pkMain,Integer billEndTqData, Integer billEndGdmonthData, Integer billEndGddayData,List<RoomExpensesResult> expensesList, HouseBill houseBill) {
//        //保存租金账单明细信息
//        BigDecimal subtotalsd=new BigDecimal(0.00);
//        String snowflakesIdsd = IdFlowingUtil.getSnowflakesId("QYZDSD");
//        houseBill.setHouseLeaseId(pkMain);
//
//        houseBill.setNo(snowflakesIdsd);
//        //创建收租日期
//        createRentedDay(0, billEndTqData, billEndGdmonthData, billEndGddayData, houseBill);
//        houseBill.setSubtotal(new BigDecimal(0.00));
//        houseBill.setBillStatus(0);
//        houseBill.setStatus(1);
//        houseBill.setCreateTime(date);
//        int qsnum = houseBill.getQsnum();
//        if(qsnum==1){
//            //才有效
//            houseBill.setStatus(0);
//        }
//        houseBill.setCreateTime(date);
//        houseBill.setCreateUser(sysLoginUserId);
//        Long billPksd = houseBillService.add(houseBill);
//        houseBill.setId(billPksd);
//        //房间费用类详情
//        subtotalsd = addExpensesDetailZjzd(houseLease,DateUtil.format(houseBill.getRentedDay(),"yyyy-MM-dd"),qsnum,date, sysLoginUserId, expensesList, subtotalsd, snowflakesIdsd, billPksd);
//        houseBill.setSubtotal(subtotalsd);
//        dbUtils.update(houseBill);
//    }
//
//    private void addBillBysDNo(int amount,int calculateStyle,HouseBill houseBill,HouseLease houseLease,Date date,Long sysLoginUserId,
//                               long pkMain,int receiptYj,int billEndType,Integer billEndTqData,
//                               Integer billEndGdmonthData,Integer billEndGddayData,
//                               List<RoomDepositResult> depositList,List<RoomExpensesResult> expensesList) {
//        //保存账单明细信息
//        BigDecimal subtotal=new BigDecimal(0.00);
//        String snowflakesId = IdFlowingUtil.getSnowflakesId("QYZDZJ");
//        houseBill.setHouseLeaseId(pkMain);
//        houseBill.setNo(snowflakesId);
//        //创建收租日期
//        createRentedDay(billEndType, billEndTqData, billEndGdmonthData, billEndGddayData, houseBill);
//        houseBill.setSubtotal(new BigDecimal(0.00));
//        houseBill.setBillStatus(0);
//        houseBill.setStatus(1);
//        houseBill.setCreateTime(date);
//        int qsnum = houseBill.getQsnum();
//        if(qsnum==1){
//            //才有效
//            houseBill.setStatus(0);
//        }
//        houseBill.setCreateUser(sysLoginUserId);
//        Long billPk = houseBillService.add(houseBill);
//        houseBill.setId(billPk);
//        //租金
//        subtotal = addZjDetail(amount,calculateStyle,houseBill,houseLease, date, sysLoginUserId, subtotal, snowflakesId, billPk);
//        //押金类账单详情
//
//        if(qsnum==1){
//            //添加第一期账单调整日志表
//            BillRentAdjustmentParam billRentAdjustmentParam=new BillRentAdjustmentParam();
//            billRentAdjustmentParam.setLeaseId(houseLease.getId());
//            billRentAdjustmentParam.setQsnum(1);
//            billRentAdjustmentParam.setName("租金1期"+DateUtil.format(houseBill.getRentStartDate(),"yyyy-MM-dd"));
//            billRentAdjustmentParam.setBillDate(DateUtil.format(houseBill.getRentedDay(),"yyyy-MM-dd"));
//            billRentAdjustmentParam.setAdjustmentType(1); // 簽約
//            billRentAdjustmentParam.setChangeMoney(new BigDecimal(0.00));
//            billRentAdjustmentParam.setRent(houseLease.getRent());
//            billRentAdjustmentParam.setRentStartDate(DateUtil.format(houseBill.getRentStartDate(),"yyyy-MM-dd"));
//            billRentAdjustmentParam.setRentEndDate(DateUtil.format(houseBill.getRentEndDate(),"yyyy-MM-dd"));
//            billRentAdjustmentService.add(billRentAdjustmentParam);
//            //只有第一期才有押金 才有效
//            subtotal =addYjBillDetaill(houseLease, date, sysLoginUserId, depositList, subtotal, snowflakesId, billPk);
//        }
//        //房间费用类详情
//        subtotal =addExpensesDetail(houseLease,DateUtil.format(houseBill.getRentedDay(),"yyyy-MM-dd"),qsnum,date, sysLoginUserId, expensesList, subtotal, snowflakesId, billPk);
//        houseBill.setSubtotal(subtotal);
//        dbUtils.update(houseBill);
//    }
//
//    private BigDecimal addZjDetail(int amount,int calculateStyle,HouseBill houseBill,HouseLease houseLease, Date date, Long sysLoginUserId, BigDecimal subtotal, String snowflakesId, Long billPk) {
//        BigDecimal rent = getRentMoney(calculateStyle,houseBill, houseLease);
//        if (amount==0){
//            //小数点后两位
//            rent=DecimalUtils.scale(rent,2);
//        }else {
//            //四舍五入
//            BigDecimal scale = DecimalUtils.scale(rent,2);
//            long l  = scale.setScale( 0, BigDecimal.ROUND_HALF_UP ).longValue(); // 四舍五入
//            rent = DecimalUtils.toBigDecimal(l);
//        }
//        HouseBillDetail houseBillDetailZj=new HouseBillDetail();
//        houseBillDetailZj.setHouseBillId(billPk);
//        houseBillDetailZj.setAmount(rent);
//        subtotal=DecimalUtils.add(subtotal, rent);
//        houseBillDetailZj.setNo(snowflakesId);
//        houseBillDetailZj.setBillInOutType(1);
//        //押金 1  水電 2  3 （租金、4临时收入、5临时支出）
//        houseBillDetailZj.setDepositHydropowerFlag(3);
//        houseBillDetailZj.setRentAmountName("租金");
//        //費用類型（字典  1抄表 0不抄表） 抄表需要
//        houseBillDetailZj.setRentAmountType(0);
//        houseBillDetailZj.setStatus(0);
//        houseBillDetailZj.setCreateTime(date);
//        houseBillDetailZj.setCreateUser(sysLoginUserId);
//        houseBillDetailService.add(houseBillDetailZj);
//        return subtotal;
//    }
//
//    private BigDecimal getRentMoney(int calculateStyle,HouseBill houseBill, HouseLease houseLease) {
//        Date rentStartDate = houseBill.getRentStartDate();
//        Date rentEndDate = houseBill.getRentEndDate();
//        int receiptFu = houseLease.getReceiptFu();
//        int receiptYj = houseLease.getReceiptYj();
//        BigDecimal rent = houseLease.getRent();
//        if (receiptYj == 1){
//            int betweenDay = (int)DateUtil.betweenDay(rentStartDate, rentEndDate, true)+1;
//            return DecimalUtils.multiple(rent,betweenDay);
//        }else if (receiptYj ==2){
//            //正常是1个月
//            return getBigDecimalByMonths(calculateStyle, receiptFu, rent,DateUtil.format(rentStartDate,"yyyy-MM-dd"),DateUtil.format(rentEndDate,"yyyy-MM-dd"));
//        }else if (receiptYj ==3){
//            return  getBigDecimalByYears(calculateStyle, receiptFu, rent,DateUtil.format(rentStartDate,"yyyy-MM-dd"),DateUtil.format(rentEndDate,"yyyy-MM-dd"));
//        }
//        return rent;
//    }
//
//
//    /**
//     * 房间费用类详情
//     * @param date
//     * @param sysLoginUserId
//     * @param expensesList
//     * @param subtotal
//     * @param snowflakesId
//     * @param billPk
//     */
//    private BigDecimal addExpensesDetail(HouseLease houseLease,String rentDay,int billQs,
//                                         Date date, Long sysLoginUserId, List<RoomExpensesResult> expensesList, BigDecimal subtotal, String snowflakesId, Long billPk) {
//        for (int i = 0; i < expensesList.size(); i++) {
//            RoomExpensesResult item = expensesList.get(i);
//            HouseBillDetail houseBillDetail = new HouseBillDetail();
//            houseBillDetail.setHouseBillId(billPk);
//            houseBillDetail.setAmount(item.getAmount());
//            subtotal = DecimalUtils.add(subtotal,item.getAmount());
//            houseBillDetail.setNo(snowflakesId);
//            houseBillDetail.setBillInOutType(1);
//            //押金 1  水電 2  3 租金、4临时收入、5临时支出
//            houseBillDetail.setDepositHydropowerFlag(2);
//            houseBillDetail.setExpensesType(item.getType());
//            houseBillDetail.setRentAmountCategory(item.getId());
//            houseBillDetail.setRentAmountName(item.getName());
//            //費用類型（字典  1抄表 0不抄表） 抄表需要
//            int type = item.getType();
//            if (type == 2) {
//                houseBillDetail.setRentAmountType(1);
//            } else {
//                houseBillDetail.setRentAmountType(0);
//            }
//            houseBillDetail.setStatus(0);
//            houseBillDetail.setCreateTime(date);
//            houseBillDetail.setCreateUser(sysLoginUserId);
//            Long key = houseBillDetailService.add(houseBillDetail);
//            if (type == 2) {
//                //保存抄表初始記錄
//                HydropowerMeterParam hydropowerMeterParam=new HydropowerMeterParam();
////                hydropowerMeterParam.setEstateId();
//                hydropowerMeterParam.setSolder(item.getSolder());
//                hydropowerMeterParam.setAmount(item.getAmount());
//                hydropowerMeterParam.setEstateRoomName(houseLease.getRoomName());
//                hydropowerMeterParam.setRoomId(houseLease.getRoomId());
//                hydropowerMeterParam.setReservation(houseLease.getName());
//                hydropowerMeterParam.setRentedDay(rentDay);
//                hydropowerMeterParam.setHouseBillId(billPk);
//                hydropowerMeterParam.setType(item.getType());
//                hydropowerMeterParam.setTypeName(item.getName());
//                hydropowerMeterParam.setPreReading(new BigDecimal(0.00));
//                hydropowerMeterParam.setReading(new BigDecimal(0.00));
//                hydropowerMeterParam.setDosage(new BigDecimal(0.00));
//                hydropowerMeterParam.setCost(new BigDecimal(0.00));
//                hydropowerMeterParam.setMeterStatus("初始讀數");
//                hydropowerMeterParam.setHouseBillDetailId(key);
//                if (billQs==1){
//                    hydropowerMeterParam.setStatus(0);
//                }else {
//                    hydropowerMeterParam.setStatus(3);
//                }
//                hydropowerMeterService.add(hydropowerMeterParam);
//            }
//        }
//        return subtotal;
//    }
//  /**
//     * 房间费用类详情
//     * @param date
//     * @param sysLoginUserId
//     * @param expensesList
//     * @param subtotal
//     * @param snowflakesId
//     * @param billPk
//     */
//    private BigDecimal addExpensesDetailZjzd(HouseLease houseLease,String rentedDay,int billQs,
//                                             Date date, Long sysLoginUserId, List<RoomExpensesResult> expensesList, BigDecimal subtotal, String snowflakesId, Long billPk) {
//        HouseBillDetail houseBillDetail=null;
//        for (int i = 0; i < expensesList.size(); i++) {
//            RoomExpensesResult item = expensesList.get(i);
//            houseBillDetail= new HouseBillDetail();
//            houseBillDetail.setHouseBillId(billPk);
//            houseBillDetail.setAmount(item.getAmount());
//            subtotal =DecimalUtils.add(subtotal,item.getAmount());
//            houseBillDetail.setNo(snowflakesId);
//            houseBillDetail.setBillInOutType(1);
//            //押金 1  水電 2 其他 3 （租金、临时收入、临时支出）
//            houseBillDetail.setDepositHydropowerFlag(2);
//            houseBillDetail.setExpensesType(item.getType());
//            houseBillDetail.setRentAmountCategory(item.getId());
//            houseBillDetail.setRentAmountName(item.getName());
//            //費用類型（字典  1抄表 0不抄表） 抄表需要
//            int type = item.getType();
//            if (type == 2) {
//                houseBillDetail.setRentAmountType(1);
//            } else {
//                houseBillDetail.setRentAmountType(0);
//            }
//            houseBillDetail.setStatus(0);
//            houseBillDetail.setCreateTime(date);
//            houseBillDetail.setCreateUser(sysLoginUserId);
//            Long key = houseBillDetailService.add(houseBillDetail);
//            if (type == 2) {
//                //保存抄表初始記錄
//                HydropowerMeterParam hydropowerMeterParam=new HydropowerMeterParam();
////                hydropowerMeterParam.setEstateId();
//                hydropowerMeterParam.setSolder(item.getSolder());
//                hydropowerMeterParam.setAmount(item.getAmount());
//                hydropowerMeterParam.setEstateRoomName(houseLease.getRoomName());
//                hydropowerMeterParam.setRoomId(houseLease.getRoomId());
//                hydropowerMeterParam.setReservation(houseLease.getName());
//                hydropowerMeterParam.setRentedDay(rentedDay);
//                hydropowerMeterParam.setHouseBillId(billPk);
//                hydropowerMeterParam.setType(item.getType());
//                hydropowerMeterParam.setTypeName(item.getName());
//                hydropowerMeterParam.setPreReading(new BigDecimal(0.00));
//                hydropowerMeterParam.setReading(new BigDecimal(0.00));
//                hydropowerMeterParam.setDosage(new BigDecimal(0.00));
//                hydropowerMeterParam.setCost(new BigDecimal(0.00));
//                hydropowerMeterParam.setMeterStatus("初始讀數");
//                hydropowerMeterParam.setHouseBillDetailId(key);
//                if (billQs==1){
//                    hydropowerMeterParam.setStatus(0);
//                }else {
//                    hydropowerMeterParam.setStatus(3);
//                }
//                hydropowerMeterService.add(hydropowerMeterParam);
//            }
//        }
//        return subtotal;
//    }
//
//    /**
//     * 押金详情
//     * @param houseLease
//     * @param date
//     * @param sysLoginUserId
//     * @param depositList
//     * @param subtotal
//     * @param snowflakesId
//     * @param billPk
//     */
//    private BigDecimal addYjBillDetaill(HouseLease houseLease, Date date, Long sysLoginUserId, List<RoomDepositResult> depositList, BigDecimal subtotal, String snowflakesId, Long billPk) {
//        for (int i = 0; i < depositList.size(); i++) {
//            RoomDepositResult it = depositList.get(i);
//
//            HouseBillDetail houseBillDetail=new HouseBillDetail();
//            houseBillDetail.setHouseBillId(billPk);
//            int deposittype = it.getDeposittype();
//            if (deposittype==1){
//                subtotal=DecimalUtils.add(subtotal,DecimalUtils.multiple(it.getAmount(),it.getQuantity()));
//                houseBillDetail.setAmount(DecimalUtils.multiple(it.getAmount(),it.getQuantity()));
//            }else {
//                subtotal=DecimalUtils.add(subtotal,it.getAmount());
//                houseBillDetail.setAmount(it.getAmount());
//            }
//            houseBillDetail.setNo(snowflakesId);
//            houseBillDetail.setBillInOutType(1);
//            //押金 1  水電 2  3 （租金、4临时收入、5临时支出）
//            houseBillDetail.setDepositHydropowerFlag(1);
//            houseBillDetail.setRentAmountCategory(it.getId());
//            houseBillDetail.setRentAmountName(it.getDepositname());
//            //費用類型（字典  1抄表 0不抄表） 抄表需要
//            houseBillDetail.setRentAmountType(0);
//            houseBillDetail.setStatus(0);
//            houseBillDetail.setCreateTime(date);
//            houseBillDetail.setCreateUser(sysLoginUserId);
//            houseBillDetailService.add(houseBillDetail);
//        }
//        HouseBillDetail houseBillDetailYj=new HouseBillDetail();
//        houseBillDetailYj.setHouseBillId(billPk);
//        houseBillDetailYj.setAmount(houseLease.getDeposit());
//        subtotal=DecimalUtils.add(subtotal,houseLease.getDeposit());
//        houseBillDetailYj.setNo(snowflakesId);
//        houseBillDetailYj.setBillInOutType(1);
//        //押金 1  水電 2 其他 3 （租金、临时收入、临时支出）
//        houseBillDetailYj.setDepositHydropowerFlag(3);
//        houseBillDetailYj.setRentAmountName("押金");
//        //費用類型（字典  1抄表 0不抄表） 抄表需要
//        houseBillDetailYj.setRentAmountType(0);
//        houseBillDetailYj.setStatus(0);
//        houseBillDetailYj.setCreateTime(date);
//        houseBillDetailYj.setCreateUser(sysLoginUserId);
//        houseBillDetailService.add(houseBillDetailYj);
//        return subtotal;
//    }
//
//    private void createRentedDay(int billEndType, Integer billEndTqData, Integer billEndGdmonthData, Integer billEndGddayData, HouseBill houseBill) {
//        if (billEndType==0){
//            Date days = com.anti.commom.core.utils.DateUtil.addDaysResDate(DateUtil.format(houseBill.getRentStartDate(), "yyyy-MM-dd"), -billEndTqData);
//            houseBill.setRentedDay(days);
//            houseBill.setShouldReceiveDate(days);
//        }else {
//            // com.anti.commom.core.utils.DateUtil.addDays()
//            Date daysOfMonth = getDaysOfMonth(houseBill.getRentStartDate(), billEndGdmonthData, billEndGddayData);
//            houseBill.setRentedDay(daysOfMonth);
//            houseBill.setShouldReceiveDate(daysOfMonth);
//        }
//    }
//
//
//    public void delete(HouseLeaseParam houseLeaseParam) {
//        String sql="delete  from house_lease where id =? ";
//        dbUtils.execSql(sql,houseLeaseParam.getId());
//    }
//
//    public void edit(HouseLeaseParam houseLeaseParam) {
//        HouseLease houseLease = this.queryHouseLease(houseLeaseParam);
//        BeanUtil.copyProperties(houseLeaseParam, houseLease);
//        dbUtils.update(houseLease);
//    }
//
//    @Override
//    public HouseLease detail(HouseLeaseParam houseLeaseParam) {
//        return this.queryHouseLease(houseLeaseParam);
//    }
//
//    @Override
//    public HouseLeaseResult getIsLeaseMsgForPrint(Long id) {
//        String sql="select * from house_lease where id =? ";
//        HouseLeaseResult houseLeaseResult = dbUtils.get(sql, HouseLeaseResult.class, id);
//        Long roomId = houseLeaseResult.getRoomId();
//        List<HouseLeaseLive> houseLeaseLives = houseLeaseLiveService.listByLeaseId(houseLeaseResult.getId());
//        houseLeaseResult.setLeaseLiveData(houseLeaseLives);
//        List<RoomDepositResult> depositListByRoomId = roomDepositService.getDepositListByRoomId(roomId);
//        houseLeaseResult.setYjList(depositListByRoomId);
//        List<RoomExpensesResult> expensesListByRoomId = roomExpensesService.getExpensesListByRoomId(roomId);
//        houseLeaseResult.setFyList(expensesListByRoomId);
//        List<RoomFurnitureResult> roomFurnitureListByRoomId = roomFurnitureService.getRoomFurnitureListByRoomId(roomId);
//        houseLeaseResult.setJsList(roomFurnitureListByRoomId);
//        return houseLeaseResult;
//    }
//
//    /**
//     * 获取房间租约
//     *
//     * @author anti
//     * @date 2021-05-06 09:30:21
//     */
//    private HouseLease queryHouseLease(HouseLeaseParam houseLeaseParam) {
//        HouseLease houseLease = this.getById(houseLeaseParam);
//        if (ObjectUtil.isNull(houseLease)) {
//            throw new BusinessException(HouseLeaseExceptionEnum.NOT_EXIST);
//        }
//        return houseLease;
//    }
//
//    private void checkParam(HouseLeaseParam houseLeaseParam, boolean isExcludeSelf){
//        Long id = houseLeaseParam.getRoomId();
//
//        //构建带name查询条件
//        StringBuilder nameSb=new StringBuilder("select count(*) from bus_room where status =0 and  lease =1 and id =? ");
//
//        //查询重复记录的数量
//        int countByName = dbUtils.getIntValue(nameSb.toString(),id);
//
//        //如果存在重复的记录，抛出异常，直接返回前端
//        if (countByName >= 1) {
//            throw new BusinessException(0,"該房間編號已經被签约，請重新選擇");
//        }
//    }
//
//    public List<HouseBill> calculateQs(Date rentStartDate,Date rentEndDate,int receiptFu,int receiptYj){
//        List<HouseBill> houseBillList  = new ArrayList<HouseBill>();
//        List<TimeVo> days=new ArrayList<>();
//        // 计算设置
//        if (1 == receiptYj){
//            days = getDays(receiptFu,DateUtil.format(rentStartDate,"yyyy-MM-dd"), DateUtil.format(rentEndDate,"yyyy-MM-dd"));
//        }else if (2 == receiptYj){
//            days = getMonths(receiptFu,DateUtil.format(rentStartDate,"yyyy-MM-dd"), DateUtil.format(rentEndDate,"yyyy-MM-dd"));
//        }else if (3 == receiptYj){
//            days = getYears(receiptFu,DateUtil.format(rentStartDate,"yyyy-MM-dd"), DateUtil.format(rentEndDate,"yyyy-MM-dd"));
//        }else {
//            TimeVo timeVo=new TimeVo();
//            timeVo.setStart(rentStartDate);
//            timeVo.setEnd(rentEndDate);
//            days.add(timeVo);
//        }
//        days.forEach(date -> {
//            HouseBill houseBill=new HouseBill();
//            houseBill.setRentStartDate(date.getStart());
//            houseBill.setRentEndDate(date.getEnd());
//            houseBillList.add(houseBill);
//        });
//        return houseBillList;
//    }
//
//
//    public  static Date getDaysOfMonth(Date date,int offSetMon,int day) {
//        DateTime dateTime = DateUtil.offsetMonth(date, offSetMon);
//        int daysOfMonth = getDaysOfMonth(date);
//        String format="";
//        if (day<10){
//            format = DateUtil.format(dateTime, "yyyy-MM")+"-0"+day;
//        }else if (day>daysOfMonth){
//            format = DateUtil.format(dateTime, "yyyy-MM")+"-"+daysOfMonth;
//        }else {
//            format = DateUtil.format(dateTime, "yyyy-MM")+"-"+day;
//        }
//        return  DateUtil.parse(format, "yyyy-MM-dd");
//    }
//    public  static int getDaysOfMonth(Date date) {
//        Calendar calendar =Calendar.getInstance();
//        calendar.setTime(date);
//        return calendar.getActualMaximum(Calendar.DAY_OF_MONTH);
//    }
//
//    public static List<TimeVo> getDays(int num,String startTime, String endTime) {
//        // 返回的日期集合
//        List<TimeVo> list=new ArrayList<>();
//        DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
//        try {
//            Date start = dateFormat.parse(startTime);
//            Date end = dateFormat.parse(endTime);
//            Calendar tempStart = Calendar.getInstance();
//            tempStart.setTime(start);
//            Calendar tempEnd = Calendar.getInstance();
//            tempEnd.setTime(end);
//            getNextDaysDay(tempStart,tempEnd,num,list);
//        } catch (ParseException e) {
//            e.printStackTrace();
//        }
//        return list;
//    }
//    static void getNextDaysDay(Calendar start,Calendar end,int num,List<TimeVo> list){
//        Date startTime = start.getTime();
//        start.add(Calendar.DATE, num-1);
//        Date startTime1 = start.getTime();
//        if (start.before(end)){
//            TimeVo timeVo=new TimeVo();
//            timeVo.setStart(startTime);
//            timeVo.setEnd(startTime1);
//            start.add(Calendar.DATE, 1);
//            start.getTime();
//            list.add(timeVo);
//            getNextDaysDay(start,end,num,list);
//        }else {
//            TimeVo timeVo=new TimeVo();
//            timeVo.setStart(startTime);
//            timeVo.setEnd(end.getTime());
//            list.add(timeVo);
//            return ;
//        }
//    }
//    public static List<TimeVo> getMonths(int num,String startTime, String endTime) {
//        // 返回的日期集合
//        List<TimeVo> list=new ArrayList<>();
//        DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
//        try {
//            Date start = dateFormat.parse(startTime);
//            Date end = dateFormat.parse(endTime);
//            Calendar tempStart = Calendar.getInstance();
//            tempStart.setTime(start);
//            Calendar tempEnd = Calendar.getInstance();
//            tempEnd.setTime(end);
//            getNextMonthDay(tempStart,tempEnd,num,list);
//        } catch (ParseException e) {
//            e.printStackTrace();
//        }
//        return list;
//    }
//
//    public static void getNextMonthDay(Calendar start,Calendar end,int num,List<TimeVo> list){
//        Date startTime = start.getTime();
//        start.add(Calendar.MONTH, num);
//        start.add(Calendar.DATE, -1);
//        Date startTime1 = start.getTime();
//        if (start.before(end)){
//            TimeVo timeVo=new TimeVo();
//            timeVo.setStart(startTime);
//            timeVo.setEnd(startTime1);
//            start.add(Calendar.DATE, 1);
//            start.getTime();
//            list.add(timeVo);
//            getNextMonthDay(start,end,num,list);
//        }else {
//            TimeVo timeVo=new TimeVo();
//            timeVo.setStart(startTime);
//            timeVo.setEnd(end.getTime());
//            list.add(timeVo);
//            return ;
//        }
//    }
//
//    public static List<TimeVo> getYears(int num,String startTime, String endTime) {
//        // 返回的日期集合
//        List<TimeVo> list=new ArrayList<>();
//        DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
//        try {
//            Date start = dateFormat.parse(startTime);
//            Date end = dateFormat.parse(endTime);
//            Calendar tempStart = Calendar.getInstance();
//            tempStart.setTime(start);
//            Calendar tempEnd = Calendar.getInstance();
//            tempEnd.setTime(end);
//            getNextYearsDay(tempStart,tempEnd,num,list);
//        } catch (ParseException e) {
//            e.printStackTrace();
//        }
//        return list;
//    }
//
//    static void getNextYearsDay(Calendar start,Calendar end,int num,List<TimeVo> list){
//        Date startTime = start.getTime();
//        start.add(Calendar.YEAR, num);
//        start.add(Calendar.DATE, -1);
//        Date startTime1 = start.getTime();
//        if (start.before(end)){
//            TimeVo timeVo=new TimeVo();
//            timeVo.setStart(startTime);
//            timeVo.setEnd(startTime1);
//            start.add(Calendar.DATE, 1);
//            start.getTime();
//            list.add(timeVo);
//            getNextMonthDay(start,end,num,list);
//        }else {
//            TimeVo timeVo=new TimeVo();
//            timeVo.setStart(startTime);
//            timeVo.setEnd(end.getTime());
//            list.add(timeVo);
//            return ;
//        }
//    }
//
//    public static void main(String[] args) {
//        //2021-07-07~2021-08-06 	2021-11-01~2022-01-31
//        BigDecimal bigDecimalByMonths = getBigDecimalByYears(0, 3, new BigDecimal(900),"2021-05-05", "2021-05-05");
//        System.out.println(bigDecimalByMonths);
//
//    }
//    private static BigDecimal getBigDecimalByMonths(int calculateStyle, int receiptFu, BigDecimal rent,String startTime,String endTime) {
//        List<TimeVo> months = getMonths(1, startTime,endTime );
//        int size = months.size();
//        int lastMonth=months.size()-1;
//        TimeVo timeVo = months.get(lastMonth);
//        DayCompare dayCompare = dayComparePrecise(timeVo.getStart(), timeVo.getEnd());
//        //正好一个账单周期
//        if (size==receiptFu){
//            int ysall = dayCompare.getMonth();
//            //判断最后一个月是否满足一个月
//            if (ysall==1){
//                //足月
//                BigDecimal multiply = DecimalUtils.multiple(rent, receiptFu);
//                return multiply;
//            }else {
//                int mothDays=30;
//                if (calculateStyle!=0){
//                    Date start = timeVo.getStart();
//                    mothDays = com.anti.commom.core.utils.DateUtil.getCurrentMonthDayNum(start);
//                }
//                BigDecimal divide = DecimalUtils.divide(rent,new BigDecimal(mothDays));
//                BigDecimal multiple = DecimalUtils.multiple(divide, dayCompare.getDay());
//                return multiple;
//            }
//        }else {
//            BigDecimal multiple = DecimalUtils.multiple(rent,(size-1));
//            //不足一个账单周期
//            int mothDays=30;
//            if (calculateStyle!=0){
//                Date start = timeVo.getStart();
//                mothDays = com.anti.commom.core.utils.DateUtil.getCurrentMonthDayNum(start);
//            }
//            BigDecimal divide = DecimalUtils.divide(rent,new BigDecimal(mothDays));
//            BigDecimal multiply = DecimalUtils.multiply(divide, new BigDecimal(dayCompare.getDay()));
//            BigDecimal add = DecimalUtils.add(multiply, multiple);
//            return add;
//        }
//    }
//
//    private static BigDecimal getBigDecimalByYears(int calculateStyle, int receiptFu, BigDecimal rent,String startTime,String endTime) {
//        //不足一个月按一个月付
//        List<TimeVo> months = getMonths(1, startTime,endTime);
//        int size = months.size();
//        BigDecimal divide = DecimalUtils.divide(rent,new BigDecimal(12));
//        BigDecimal multiply = DecimalUtils.multiple(divide, size);
//        return multiply;
//    }
//    /**
//     * 计算2个日期之间相差的  相差多少年月日
//     * @param fromDate
//     * @param toDate
//     * @return
//     */
//    public static DayCompare dayComparePrecise(Date fromDate,Date toDate){
//        //////////////////////////////
//        int betweenDay = (int)DateUtil.betweenDay(fromDate, toDate, true)+1;
////        int betweenMonth = (int)DateUtil.betweenMonth(fromDate, toDate, true);
//        int mothDays = com.anti.commom.core.utils.DateUtil.getCurrentMonthDayNum(fromDate);
//        int betweenMonth=0;
//        if (betweenDay==mothDays){
//            mothDays=1;
//        }
//        return DayCompare.builder().day(betweenDay).month(betweenMonth).year(0).build();
//    }
//
//    public static void mains(String[] args) {
//        //2021-07-07~2021-08-06 	2021-11-01~2022-01-31
//        DayCompare dayCompare = dayComparePrecise(DateUtil.parse("2021-02-01","yyyy-MM-dd"), DateUtil.parse("2021-02-28","yyyy-MM-dd"));
//        System.out.println(2121);
//
//    }
//
//    public String getZqName(HouseLeaseParam houseLeaseParam){
//        // 依据（字典 1日 2月 3年 4一次付清）
//        int receiptyj = houseLeaseParam.getReceiptYj();
//        // 付 （字典 付1-付18）
//        int receiptfu = houseLeaseParam.getReceiptFu();
//        // 押 （字典 押1-押18-自定义19）
//        int receiptya = houseLeaseParam.getReceiptYa();
//        if (receiptyj == 4){
//            return "一次付清";
//        }
//        String dw="月";
//        if (receiptyj == 1){
//            dw="日";
//        }else if (receiptyj == 2){
//            dw="月";
//        }else if (receiptyj == 3){
//            dw="年";
//        }
//
//        if (receiptya==19){
//            return "付"+receiptfu+dw+" 押金自定義";
//        }
//        return "付"+receiptfu+dw+" 押"+receiptya+dw;
//    }
//}
